package com.web;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.entity.Employee;
import com.service.EmployeeService;
import com.util.Content;
import com.util.UUID;

public class AddMember extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		String name=request.getParameter("username");
		name=new String(name.getBytes("ISO8859-1"),"UTF-8");
		name = Content.replace(name);
		String password="1";
		
		//name=new String(name.getBytes("ISO-8859-1"),"UTF-8");
		
		EmployeeService employeeService=new EmployeeService();
		List<Employee> lists=employeeService.getAll();
		boolean flag=true;
		for(Employee e:lists){
			if (e.getUsername().equals(name)) {
				flag=false;
				break;
			}
		}
		
		if (flag) {
			Employee employee=new Employee();
			employee.setUsername(name);
			employee.setPassword(password);
			employee.setId(UUID.getUUID());
			employee.setPic("img/a.png");
			
			employeeService.add(employee);
		}
		
		response.sendRedirect("projectlist.jspx");
	}

}
